<template>
  <div>
    <div class="slot">
      <div class="top">
        <div class="return" @click="goback">
          <img src="@/assets/my/zuo.png" alt />
        </div>
        <span>订单详情</span>
      </div>
    </div>

    <div class="main">
      <!-- 待发货 -->
      <div class="main_top" v-if="orderinfo.status==3">
        <div class="icon">
          <img src="@/assets/pblic/dfh.png" alt />
        </div>
        <div class="p">
          <div class="p1">待发货</div>
          <div class="p2">买家已付款，等待商家发货</div>
        </div>
      </div>
       <!-- 已出单 -->
      <div class="main_top" v-if="orderinfo.status==8">
        <div class="icon">
          <img src="@/assets/pblic/dfh.png" alt />
        </div>
        <div class="p">
          <div class="p1">已出单</div>
          <div class="p2">商家已出单，等待发货</div>
        </div>
      </div>
      <!-- 待收货 -->
      <div class="main_top" v-if="orderinfo.status==4">
        <div class="icon">
          <img src="@/assets/pblic/dsh.png" alt />
        </div>
        <div class="p">
          <div class="p1">已发货</div>
          <div class="p2">商家已发货，等待买家收货</div>
        </div>
      </div>
      <!-- 待自提 -->
      <div class="main_top" v-if="orderinfo.status==2">
        <div class="icon">
          <img src="@/assets/pblic/dzt.png" alt />
        </div>
        <div class="p">
          <div class="p1">待自提</div>
          <div class="p2">商家已完成备货，等待买家上门自提</div>
        </div>
      </div>
       <!-- 售后中 -->
      <div class="main_top" v-if="orderinfo.status==6">
        <div class="icon">
          <img src="@/assets/pblic/dfh.png" alt />
        </div>
        <div class="p">
          <div class="p1">售后中</div>
          <div class="p2">等待平台审核</div>
        </div>
      </div>
       <!-- 已完成 -->
      <div class="main_top" v-if="orderinfo.status==5">
        <div class="icon">
          <img src="@/assets/pblic/dfh.png" alt />
        </div>
        <div class="p">
          <div class="p1">已完成</div>
          <div class="p2">谢谢</div>
        </div>
      </div>
      <!-- 已完成 -->
      <div class="main_top" v-if="orderinfo.status==9">
        <div class="icon">
          <img src="@/assets/pblic/dfh.png" alt />
        </div>
        <div class="p">
          <div class="p1">取消申请中</div>
          <div class="p2">等待平台审核</div>
        </div>
      </div>
      <!-- 待发货/待收货 地址 -->
      <div class="address" v-if="orderinfo.status==3 || orderinfo.status==4 || orderinfo.status==6">
        <div class="address_main">
          <div class="icon">
            <img src="@/assets/pblic/dzh.png" alt />
          </div>
          <div class="p">
            <div class="p1">
              {{orderinfo.address.name}}
              <span>{{orderinfo.address.phone}}</span>
            </div>
            <div
              class="p2"
            >{{orderinfo.address.province}}{{orderinfo.address.city}}{{orderinfo.address.area}}{{orderinfo.address.detail}}</div>
          </div>
        </div>
      </div>
      <!-- 待自提仓库 -->
      <div class="address" v-if="orderinfo.status==2">
        <div class="address_main">
          <div class="icon">
            <img src="@/assets/pblic/ck.png" alt />
          </div>
          <div class="p">
            <div class="p1">{{orderinfo.warehouse.name}}</div>
            <div
              class="p2"
            >{{orderinfo.warehouse.province}}{{orderinfo.warehouse.city}}{{orderinfo.warehouse.area}}{{orderinfo.warehouse.detail}}</div>
          </div>
        </div>
      </div>
      <div class="li_cent" v-for="(item,index) in orderinfo.goods" :key="index">
        <div class="img">
          <img :src="item.image?item.image:''" alt />
        </div>
        <div class="shop_info">
          <div class="shop_name">
            <div class="name">{{item.title}}</div>
            <div class="jiage">￥{{item.price}}</div>
          </div>
          <div class="shop_price">肉质鲜嫩</div>
          <div class="cd_info">
            <div class="shop_spec">已选：{{item.num}}{{item.unit}}</div>
          </div>
        </div>
      </div>
      <div class="price">
        <div class="price_main">
          <div>运费</div>
          <div>￥{{orderinfo.freight}}</div>
        </div>
      </div>
      <div class="price">
        <div class="price_main">
          <div>商品总额</div>
          <div>￥{{orderinfo.total}}</div>
        </div>
      </div>
      <!-- 待收货物流 -->
      <div class="wuliu" v-if="orderinfo.status==4 || orderinfo.status==5">
        <div class="wuliu_main">
          <div>物流公司：{{orderinfo.express_name?orderinfo.express_name:'无'}}</div>
          <div>物流单号：{{orderinfo.express_num}}</div>
          <div>发货时间：{{orderinfo.send_time}}</div>
        </div>
      </div>
      <!-- 待自提 提货码 -->
      <div class="ma" v-if="orderinfo.status==2">
        <div class="zitizhe"></div>
        <div class="zitima">
          <div class="zitima_main">
            <div>
              提货码：
              <span>{{orderinfo.delivery_code}}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="other">
        <div class="other_main">
          <div>订单编号：{{orderinfo.order_no}}</div>
          <div>下单时间：{{orderinfo.add_time}}</div>
          <div v-if="orderinfo.status==6">补货数量：{{orderinfo.orderAfter.num}}</div>
          <div v-if="orderinfo.status==6" class="detail">补货描述：{{orderinfo.orderAfter.detail}}</div>
        </div>
      </div>
    </div>
    <!-- 待发货/待自提 -->
    <div class="btn" v-if="orderinfo.status==2 || orderinfo.status==3">
      <div class="btn_main">
        <div class="quxbtn" @click="quxiaodd">取消订单</div>
      </div>
    </div>
    <!-- 待收货 -->
    <div class="btn" v-if="orderinfo.status==4">
      <div class="btn_main">
        <div class="quxbtn" @click="shouhou">售后补货</div>
        <div class="qurbtn" @click="querenshouhuo">确认收货</div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      orderid: 0,
      orderinfo: {},
      state: 0,
      token:"",
    };
  },
  mounted() {
    this.token = window.localStorage.getItem("token")
    this.orderid = this.$route.query.id;
    this.state = this.$route.query.state;
    console.log(this.state);
    this.getlist();
  },
  methods: {
    goback() {
      this.$router.push({
        path: "/allorder",
        query: { state: this.state },
      });
    },
    getlist() {
      axios
        .post("/index/order/info", this.$qs.stringify({
          token: this.token,
          id: this.orderid,
        }))
        .then((res) => {
          console.log(res.data.data, 111);
          this.orderinfo = res.data.data;
        });
    },
    quxiaodd() {
      axios
        .post("/index/order/cancel", this.$qs.stringify({
          token: this.token,
          order_id: this.orderid,
        }))
        .then((res) => {
          this.$toast(res.data.msg);
          this.goback()
        });
    },
    shouhou() {
      this.$router.push({
        path: "/aftereplenish",
        query: { orderid: this.orderid ,state:this.state},
      });
    },
    querenshouhuo() {
      axios
        .post("/index/order/receive", this.$qs.stringify({
          token:this.token,
          order_id:this.orderid,
        }))
        .then((res) => {
          if (res.data.code == 1) {
            this.$toast('成功');
            this.goback()
          } else {
            this.$toast('失败');
          }
        });
    },
  },
  beforeCreate() {
    document
      .querySelector("body")
      .setAttribute("style", "background-color:#F8F8F8");
  },
  beforeDestroy() {
    document.querySelector("body").setAttribute("style", "");
  },
};
</script>

<style lang="scss" scoped>
.slot {
  width: 100%;
  height: 44px;
  .top {
    width: 100%;
    height: 44px;
    display: flex;display: -webkit-flex;
    justify-content: center;
    align-items: center;
    background: white;
    position: fixed;
    top: 0;
    left: 0;
    .return {
      width: 38px;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      display: flex;display: -webkit-flex;
      justify-content: center;
      align-items: center;
      img {
        width: 8px;
        height: 15px;
      }
    }
    span {
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #000000;
      line-height: 44px;
    }
  }
}
.main {
  width: 100%;
  margin-bottom: 50px;
  .main_top {
    width: 100%;
    height: 100px;
    background: linear-gradient(90deg, #fdc80c, #ff7618);
    display: flex;display: -webkit-flex;
    align-items: center;
    .icon {
      width: 29px;
      height: 25px;
      margin-left: 15px;
      img {
        width: 100%;
      }
    }
    .p {
      margin-left: 12px;
      .p1 {
        font-size: 18px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #ffffff;
        line-height: 18px;
      }
      .p2 {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #ffffff;
        line-height: 14px;
        opacity: 0.8;
        margin-top: 10px;
      }
    }
  }
  .address {
    width: 100%;
    background: #ffffff;
    border-radius: 15px 15px 0px 0px;
    .address_main {
      width: 345px;
      margin: auto;
      display: flex;display: -webkit-flex;
      align-items: center;
      .icon {
        width: 30px;
        height: 30px;
        margin-right: 10px;
        img {
          width: 100%;
        }
      }
      .p {
        margin: 18px 0;
        .p1 {
          font-size: 16px;
          font-family: PingFang SC;
          font-weight: bold;
          color: #222222;
          line-height: 16px;
          span {
            font-weight: 500;
            font-size: 14px;
            line-height: 14px;
          }
        }
        .p2 {
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #666666;
          line-height: 12px;
          margin-top: 11px;
        }
      }
    }
  }
  .li_cent {
    width: 100%;
    height: 96px;
    background: white;
    border-bottom: 1px solid #f8f8f8;
    display: flex;display: -webkit-flex;
    align-items: center;
    border-top: 8px solid #f8f8f8;
    .img {
      width: 75px;
      height: 75px;
      overflow: hidden;
      margin-left: 20px;
      img {
        width: 100%;
      }
    }
    .shop_info {
      width: 250px;
      margin-left: 15px;
      .shop_name {
        width: 100%;
        display: flex;display: -webkit-flex;
        align-items: center;
        justify-content: space-between;
        .name {
          font-size: 14px;
          font-family: PingFang SC;
          font-weight: bold;
          color: #222527;
          line-height: 14px;
        }
        .jiage {
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #9a9a9a;
          line-height: 13px;
        }
      }
      .shop_price {
        font-size: 11px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #9a9a9a;
        line-height: 11px;
        margin-top: 10px;
      }
      .cd_info {
        width: 100%;
        display: flex;display: -webkit-flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 17px;
        .shop_spec {
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #9a9a9a;
          line-height: 12px;
        }
      }
    }
  }
  .price {
    width: 100%;
    height: 47px;
    background: white;
    .price_main {
      width: 345px;
      height: 100%;
      margin: auto;
      border-bottom: 1px solid #f8f8f8;
      display: flex;display: -webkit-flex;
      justify-content: space-between;
      align-items: center;
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #222222;
      line-height: 15px;
    }
  }
  .wuliu {
    width: 100%;
    height: 111px;
    background: #ffffff;
    border-top: 8px solid #f8f8f8;
    .wuliu_main {
      width: 345px;
      margin: auto;
      height: 100%;
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #9a9a9a;
      line-height: 15px;
      display: flex;display: -webkit-flex;
      flex-direction: column;
      justify-content: space-evenly;
    }
  }
  .ma {
    width: 100%;
    height: 45px;
    position: relative;
    .zitizhe {
      width: 100%;
      height: 45px;
      background: #4a78f7;
      opacity: 0.2;
    }
    .zitima {
      width: 100%;
      height: 45px;
      position: absolute;
      top: 0;
      left: 0;
      .zitima_main {
        width: 345px;
        height: 100%;
        margin: auto;
        display: flex;display: -webkit-flex;
        align-items: center;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #222222;
        line-height: 14px;
        span {
          font-size: 18px;
          font-weight: bold;
          color: #4a78f8;
        }
      }
    }
  }

  .other {
    width: 100%;
    height: 79px;
    background: #ffffff;
    border-top: 8px solid #f8f8f8;
    .other_main {
      width: 100%;
      margin: auto;
      height: auto;
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #9a9a9a;
      line-height: 15px;
      display: flex;display: -webkit-flex;
      flex-direction: column;
      justify-content: space-evenly;
      background: #ffffff;
      padding:0 20px 15px;
      box-sizing: border-box;
      div{
        margin-top: 15px;
        line-height: 18px;
      }
      .detail{
        letter-spacing:1px;
      }
    }
  }
}
.btn {
  width: 100%;
  height: 50px;
  background: #ffffff;
  box-shadow: 0px -1px 0px 0px rgba(0, 0, 0, 0.1);
  position: fixed;
  bottom: 0;
  left: 0;
  .btn_main {
    width: 345px;
    height: 100%;
    margin: auto;
    display: flex;display: -webkit-flex;
    align-items: center;
    justify-content: flex-end;
    .quxbtn {
      width: 90px;
      height: 34px;
      background: #ffffff;
      border: 1px solid #bfbfbf;
      border-radius: 17px;
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #444444;
      line-height: 34px;
      text-align: center;
      margin-left: 15px;
    }
    .qurbtn {
      width: 90px;
      height: 34px;
      background: #fdd40a;
      border-radius: 17px;
      line-height: 34px;
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #222222;
      text-align: center;
      margin-left: 15px;
    }
  }
}
</style>